/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __AX_UTILS_H__
#define __AX_UTILS_H__

#include <mach/debug.h>

typedef int (*os_wait_cond_func_t)(const void *param);
typedef struct os_wait {
	void *wait;
} os_wait_t;

int os_wait_init(os_wait_t *wait);
int os_wait_interruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param);
int os_wait_uninterruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param);
int os_wait_timeout_interruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param, unsigned long ms);
int os_wait_timeout_uninterruptible(os_wait_t *wait,
	os_wait_cond_func_t func, void *param, unsigned long ms);
void os_wakeup(os_wait_t *wait);
void os_wait_destroy(os_wait_t *wait);

typedef struct os_mutex {
	void *mutex;
} os_mutex_t;
int os_mutex_init(os_mutex_t *mutex);
int os_mutex_lock(os_mutex_t *mutex);
int os_mutex_lock_interruptible(os_mutex_t *mutex);
int os_mutex_trylock(os_mutex_t *mutex);
void os_mutex_unlock(os_mutex_t *mutex);
void os_mutex_destroy(os_mutex_t *mutex);




#ifndef os_readl
#define os_readl(reg)			readl((void __iomem *)(reg))
#endif
#ifndef os_writel
#define os_writel(val, reg)		writel((val), (void __iomem *)(reg))
#endif




#define ax_err(n, x, arg...) \
	do { \
		if (n == 1) \
			PRT_ERR("[NU_ERR]"x, ##arg); \
		else if (n == 2) \
			PRT_INFO("[NU_INFO]"x, ##arg); \
	} while (0)





#define os_gfp_kernel				0
#define os_gfp_atomic				1

void *os_kzalloc(unsigned long size, unsigned int os_gfp_flag);
void *os_kmalloc(unsigned long size, unsigned int os_gfp_flag);
void os_kfree(const void *addr);
void os_getjiffies(unsigned long long *pjiffies);
void os_udelay(unsigned int usecs);
void os_mdelay(unsigned int msecs);
unsigned long os_msecs_to_jiffies(const unsigned int m);
#endif
